package com.example.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.viewpageandfragment.R;

import java.util.ArrayList;
import java.util.List;


public class ViewPageAdapter extends RecyclerView.Adapter<ViewPageAdapter.ViewPageHolder> {

    private List<String> list=new ArrayList<>();
    private List<Integer> colorList=new ArrayList<>();
    public ViewPageAdapter(){
        list.add("hello");
        list.add("pepsi");
        list.add("hello");
        list.add("coco");
        list.add("hello");
        list.add("nike");

        colorList.add(R.color.white);
        colorList.add(R.color.black);
        colorList.add(R.color.teal_200);
        colorList.add(R.color.purple_200);
        colorList.add(R.color.purple_500);
        colorList.add(R.color.purple_700);
    }

    @NonNull
    @Override
    public ViewPageHolder onCreateViewHolder(@NonNull  ViewGroup parent, int viewType) {
        return new ViewPageHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_viewpage,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull  ViewPageHolder holder, int position) {

        holder.textView.setText(list.get(position));
        holder.mContainer.setBackgroundResource(colorList.get(position));
    }


    @Override
    public int getItemCount() {
        return 6;
    }

    /**
     * viewpagehold封装
     */
    class ViewPageHolder extends RecyclerView.ViewHolder{

        TextView textView;
        RelativeLayout mContainer;

        public ViewPageHolder(@NonNull  View itemView) {
            super(itemView);
            mContainer=itemView.findViewById(R.id.container);
            textView=itemView.findViewById(R.id.tvTile);
        }
    }
}
